/*////////////////////////////////////////

		Player Default Settings
			*Configuration*
			
*/////////////////////////////////////////

GAME.CharacterDefaultData = {};

	GAME.CharacterDefaultData["Inventory"] = {};
	GAME.CharacterDefaultData["Faction"] = "Military";
	GAME.CharacterDefaultData["Flags"] = "N";
	GAME.CharacterDefaultData["Name"] = "";
	GAME.CharacterDefaultData["Model"] = "";
	GAME.CharacterDefaultData["Equipment"] = { ["Misc"] = "envi_hands", ["Secondary"] = "foo", ["Primary"] = "foo" };
	GAME.CharacterDefaultData["Gear"] ={};
	
/*////////////////////////////////////////
				Sup?
		*Client Functions/Hooks*	
		
*/////////////////////////////////////////

hook.Add("ShowSpare1", "GAME.ShowSpare1", function(ply)

	umsg.Start("InventoryOpen", ply);
	umsg.End();

end);

concommand.Add("gm_selectcharacter", function(ply, cmd, args)

	ply:SelectCharacter( args[1] );

end);

concommand.Add("gm_createcharacter", function(ply, cmd, args)

	ply:CharacterSetup();

end);
	
------------------------------------------
	
local PLAYER = FindMetaTable("Player");

hook.Add("PlayerSpawn", "GAME.PlayerSpawn", function(ply)
	
	if ply:GetVar("Nein") == nil then

		ply:CharacterInitialize();
		
	end

end);

--We will use this as a hook to call anything which needs to be called when a Character has been selected, created or what have you.
function PLAYER:CharacterInitialize()

	self:CharacterSetData( self:GetData("SelectedCharacter"), "Gear", {} );
	self:InitializeLoadout();

end

--We could just get the current character but just in case we ever needed to change another characters info.
function PLAYER:CharacterSetData(charid, index, info)

	local CharacterData = self:GetData("Characters");
		
		CharacterData[charid][index] = info;
	
	self:SetData("Characters", CharacterData, true);
	
	return self:GetData("Characters")[charid];

end

--We'll skip this from above just because getting another characters info is much more simple.
function PLAYER:CharacterGetData(index)
	
	return self:GetData("Characters")[self:GetData("SelectedCharacter")][index];
	
end

function PLAYER:CharacterSetup()
	
	if self:GetVar("PlayerData")["Characters"] == nil then self:SetData("Characters", {});end
	
	local CharacterData = self:GetData("Characters");
	local charid = #CharacterData + 1;
	
		CharacterData[charid] = {};
	
	self:SetData("Characters", CharacterData);
		
		for key, data in pairs(GAME.CharacterDefaultData) do
		
			self:CharacterSetData(charid, key, data);
		
		end
	
	self:SetData("SelectedCharacter", charid, true);
	self:CharacterInitialize();
		
	return self:GetData("Characters");
	
end

function PLAYER:SelectCharacter(charid)

	if self:GetData("Characters")[charid] then
		
		self:SetData( "SelectedCharacter", tonumber(charid), true );
		self:CharacterInitialize();
		
	end
	
	return charid;
	
end
